package me.mingshan.tree;

/**
 * @author hanjuntao
 * @date 2025/10/3 0003
 */
public class IntegerBinaryTree extends BinaryTree<Integer> {

    /**
     * 求二叉树中所有节点的和
     *
     * @return 节点和
     */
    public Integer sum() {
        if (root == null) {
            return 0;
        }

        return sum(root);
    }

    private Integer sum(Node<Integer> root) {
        if (root == null) {
            return 0;
        }
        return root.getItem() + sum(root.getLeft()) + sum(root.getRight());
    }
}
